// var generatePrime = require('./lib/generatePrime')
import generatePrime from './lib/generatePrime.js'

// var DH = require('./lib/dh')
import DH from './lib/dh.js'
// var Buffer = require('./lib/safe-buffer').Buffer
import {
	Buffer
} from './lib/safe-buffer.js'

function getDiffieHellman(mod) {
	var prime = new Buffer(primes[mod].prime, 'hex')
	var gen = new Buffer(primes[mod].gen, 'hex')

	return new DH(prime, gen)
}

var ENCODINGS = {
	'binary': true,
	'hex': true,
	'base64': true
}

function createDiffieHellman(prime, enc, generator, genc) {
	if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
		return createDiffieHellman(prime, 'binary', enc, generator)
	}

	enc = enc || 'binary'
	genc = genc || 'binary'
	generator = generator || new Buffer([2])

	if (!Buffer.isBuffer(generator)) {
		generator = new Buffer(generator, genc)
	}

	if (typeof prime === 'number') {
		return new DH(generatePrime(prime, generator), generator, true)
	}

	if (!Buffer.isBuffer(prime)) {
		prime = new Buffer(prime, enc)
	}

	return new DH(prime, generator, true)
}


// export default {
// 	// DiffieHellmanGroup,
// 	// createDiffieHellmanGroup,
// 	getDiffieHellman,
// 	createDiffieHellman,
// 	DiffieHellman
// }
exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman
exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman